<template>
    <div>
            <Card>
                <p slot="title">
				    添加版本
			    </p>
                <div>
                    <Form class="step-form" ref="dictypeData" :model="dictypeData" :rules="dictypeDataRules" :label-width="100">
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="类型名称：" prop="typeName" label-position="left" :label-width="150">
                                    <Input :disabled="hasSubmit" v-model="dictypeData.typeName" type="text" placeholder="请输入类型名称" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="类型数据：" prop="typeValue" label-position="left" :label-width="150">
                                    <Input :disabled="hasSubmit" v-model="dictypeData.typeValue" type="text" placeholder="请输入类型名称" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <FormItem >
                            <Button :disabled="hasSubmit" @click="updateData" style="width:100px;" type="primary">提交</Button>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <Button :disabled="hasSubmit" @click="goBack" style="width:100px;" >返回</Button>
                        </FormItem>
                    </Form>
                </div>
            </Card>
    </div>
</template>

<script>
import ajax from '../../../libs/axios.js'
export default {
    name: 'addUser',
    data () {
        return {
            testModelShow:false,
            symptomList:[],
            selectModel:[],
            dictypeData: {
                id:'',
                typeName:'',
                typeValue:''
            },
            dictypeDataRules: {
                typeName: [
                    { required: true, message: '请输入类型名称', trigger: 'blur'},
                    {type: 'string', max: 15, message: '不能超过15个字符', trigger: 'blur'}
                ],
                typeValue: [
                    { required: true, message: '请输入类型数据', trigger: 'blur'},
                    {type: 'string', max: 15, message: '不能超过15个字符', trigger: 'blur'}
                ]
            },
            hasSubmit: false
        }
    },
    methods: {
        // 数据初始化
        init () {
            this.$store.commit('setActiveName', 'dictypeindex');
            var id = this.$route.params.id;
            this.dictypeData.id = id;
            this.selectById(id);

        },
        selectById(id){
            var _that = this;
            var url = 'adminlogin/dic/selectDicTypeById';
            var data = {
                id: id
            };
            ajax.formRes(url, data).then(function (res) {
                if (200 == res.code) {
                    _that.dictypeData = res.data;
                } else {
                    _that.$Message.success('数据原因，请联系管理员。');
                }
            }).catch(function (res) {
                console.log('有错误信息');
            });
        },
        // 修改数据
        updateData () {
            let that = this
            that.$refs['dictypeData'].validate((valid) => {
                if (valid) {
                    that.hasSubmit = true
                    let url = 'adminlogin/dic/updateDicTypeById'
                    let data = that.dictypeData
                    ajax.formRes(url, data).then(res => {
                        // success
                        that.$Message.success('新增数据成功,页面正在跳转')
                        that.hasSubmit = false
                            let argu = {
                            }
                            that.$router.push({
                                name: 'dictypeindex',
                                params: argu
                            })
                    }).catch(res => {
                        console.log('有错误信息')
                        // fail
                    })
                } else {
                    console.log('新增失败123123。。。')
                }
            })
        },
        goBack () {
            this.$router.push({
                name: 'appversionindex'
            })
        }
        
    },
    created: function () {
        this.init()
    },
    activated: function () {
        this.init()
    }
}
</script>
<style>
    .demo-upload-list-cover{
        display: none;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0,0,0,.6);
    }
    .card-upload:hover .demo-upload-list-cover{
        display: block;
    }
    .demo-upload-list-cover i{
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        margin: 0 2px;
    }
    .demo-spin-icon-load{
        animation: ani-demo-spin 1s linear infinite;
    }
    @keyframes ani-demo-spin {
        from { transform: rotate(0deg);}
        50%  { transform: rotate(180deg);}
        to   { transform: rotate(360deg);}
    }
    .demo-spin-col{
        height: 100px;
        position: relative;
        border: 1px solid #eee;
    }
</style>

